RFID INTERFACING WITH AVR
RFID stands for Radio Frequency Identification. In this project, we will use EM-18 RFID Reader. Here you will know how to interface RFID with AVR.
Synopsis

RFID stands for Radio Frequency Identification. RFID is a basic technology that allows the identification of a device (read tag / sticker / label) to be read wirelessly by a reader (RFID reader) using radio frequency. The Tag contains a small IC containing the unique identity information. The IC is attached to an antenna which transmits its identity to a reader when it detects a reader. It detects a reader by detecting the electromagnetic energy produced by the reader. The unique identity information is transmitted as radio frequencies. The reader then converts the received radio frequencies into the identity data. Most RFID readers provide a serial interface for connecting to a microcontroller.

Some of the readers also provide another interface called the Weigand Interface. In this project, we will use EM-18 RFID Reader. EM-18 is a 125 KHz RFID Reader module and comes with both Serial and Weigand interfaces. In serial interface, the EM-18 RFID Reader provides a 12 byte data when it reads any RFID tag.

Some of the readers also provide another interface called the Weigand Interface. In this project, we will use EM-18 RFID Reader. EM-18 is a 125 KHz RFID Reader module and comes with both Serial and Weigand interfaces. In serial interface, the EM-18 RFID Reader provides a 12 byte data when it reads any RFID tag.

Description

RFID is most arguably a evolutionary wireless technology which boosted working of embedded devices up to great mark. And there is plenty of systems and devices working based on this technology.

Principle Of RFID:


Radio Frequency identification describes the system in which the identity of an individual or object is transmitted by means of a unique serial number through radio waves. Usually RFID system consists of two basic components they are

1. Tag

2. Reader

RFID tags consists of a simple Microchip which stores 12 byte unique ID and an antenna through which the unique ID is read by the reader. Whereas Reader is nothing but a specifically designed hardware module that senses the tag whenever it brought within a specific range say for example 10cms. The reader emit radio waves and receive signals back from the tag which comes with different operating frequency and sensing distance.

When a RFID tag is brought within the specific range of the reader the unique ID is sensed. After reading the ID from the tag is read by the reader and then that unique id is passed onto a controller/processor. The controller in turn performs specific action using that ID based on the written code.

The RFID tag does not need to make any electrical contact with reader.

The RFID Tag is an active device which has a chip and antenna but does not need any power and are low cost.

RFID tags are very small.

RFID READER MODULE


Pin Description


With the RFID interfacing, this article also explains the USART interrupt which is an internal interrupt. (For external interrupts, refer PIC Hardware interrupts) The internal interrupts, unlike hardware interrupts, are associated with internal peripherals of the controller. To use the USART interrupt, following registers have to be configured accordingly.

INTCON (Interrupt Control Register)


PEIE/GIEL:

This bit is used to enable/disable all the peripheral interrupts (Internal interrupts) of the controller. But GIE/GIEH bit must be set to high first.

1 = Enables all Peripheral Interrupts

0 = Disables all Peripheral Interrupts

GIE/GIEH:

This is Global Interrupt Enable bit. This bit is set to high to enable all interrupts of the PIC18F4550.

1 = Enables interrupts

0 = Disables all interrupts

PIR1 (Peripheral Interrupt Request 1)


TXIF

This is Transmission interrupt flag which is set to high when TXREG* is empty.

RCIF 

This is Reception interrupt flag which is set to low when reception is complete.

TXREG

 EUSART Transmit Register (The data to be transmitted is stored in this register)

PIE1 (Peripheral Interrupt Enable 1)


TXIE

This bit is used to enable/disable the Transmission (Tx) interrupt.

RCIE 

This bit is used to enable/disable the Reception (Rx) interrupt.

Applications

=> Product tracking

=> Access control

=> Logistics

=> Asset management

=> Identification

Proteus design for RFID interfacing with AVR


Orcad design for RFID interfacing with AVR


RFID interfacing with AVR

/*  Name     : main.c
 *  Purpose  : Source code for RFID interface with ATMEGA16.
 *  Author   : Gemicates
 *  Date     : 2017-09-11
 *  Website  : www.gemicates.org
 *  Revision : None
 */
                                              // Program to get the 12 byte string and display it on LCD by Polling method:
/*
The RFID unique code is been displayed on LCE
LCD DATA port----PORT B
ctrl port------PORT D
	rs-------PD0
	rw-------PD1
	en-------PD2
*/

#define F_CPU 8000000UL

#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

#include<avr/io.h>
#include<util/delay.h>
#define delay_ms;
#define LCD_DATA PORTA	                      // LCD data port
#define ctrl PORTB
#define en PB2		                      // enable signal
#define rw PB1		                      // read/write signal
#define rs PB0		       	              // register select signal

void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);

void usart_init();
unsigned int usart_getch();

unsigned char i, card[12];
void getcard_id(void);
void LCD_display(void);

int main(void)
{
	DDRA=0xff;		              // LCD_DATA port as output port
	DDRB=0x07;		              // ctrl as output
	init_LCD();		              // initialization of LCD
	delay_ms(50);		              // delay of 50 milliseconds
	usart_init();		              // initiailztion of USART
	LCD_write_string("Unique ID No.");    // Function to display string on LCD
	
	while(1)
	{
		getcard_id();	              // Function to get RFID card no. from serial port
		LCD_cmd(0xC0);	              // to go in second line and zeroth position on LCD
		LCD_display();		      // a function to write RFID card no. on LCD
	}
	return 0;
}

void getcard_id(void)	                      // Function to get 12 byte ID no. from rfid card
{	
	for(i=0;i<12;i++) 
	{
		card[i]= usart_getch();	      // receive card value byte by byte
	}
	return;
}

void LCD_display(void)	                      // Function for displaying ID no. on LCD
{
	for(i=0;i<12;i++)
	{
		LCD_write(card[i]);	      // display card value byte by byte
	}
	return;
}

void init_LCD(void)
{
	LCD_cmd(0x38);		              // initializtion of 16x2 LCD in 8bit mode
	_delay_ms(1);

	LCD_cmd(0x01);		              // clear LCD
	_delay_ms(1);

	LCD_cmd(0x0E);		              // cursor ON
	_delay_ms(1);

	LCD_cmd(0x80);		              // ---8 go to first line and --0 is for 0th position
	_delay_ms(1);
	return;
}

void LCD_cmd(unsigned char cmd)
{
	LCD_DATA=cmd;
	ctrl =(0<<rs)|(0<<rw)|(1<<en);	
	_delay_ms(1);
	ctrl =(0<<rs)|(0<<rw)|(0<<en);	
	_delay_ms(50);
	return;
}

void LCD_write(unsigned char data)
{
	LCD_DATA= data;
	ctrl = (1<<rs)|(0<<rw)|(1<<en);
	_delay_ms(1);
	ctrl = (1<<rs)|(0<<rw)|(0<<en);
	_delay_ms(50);			
	return ;
}

void usart_init()
{
	UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
	UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1); 
				              // Use 8-bit character sizes

	UBRRL = 0x51; 	                      // Load lower 8-bits of the baud rate value..
					      // into the low byte of the UBRR register
	UBRRH = 0x103;                        // Load upper 8-bits of the baud rate value..
                                              // into the high byte of the UBRR register
}

unsigned int usart_getch()
{
	while ((UCSRA & (1 << RXC)) == 0);   // Do nothing until data have been received..
					     // and is ready to be read from UDR
	return(UDR);                         // return the byte
}

void LCD_write_string(unsigned char *str)    // take address value of the string in pointer *str
{
	int i=0;
	while(str[i]!='\0')		     // loop will go on till the NULL characters is soon in string 
 	{
		LCD_write(str[i]);	     // sending data on LCD byte by byte
		i++;
	}
	return;
}

Error message here!

Show Error message here!


Forgot your password?

Error message here!

Send OTP

Error message here!

Show Error message here!


Lost your password? Please enter your email address. You will receive a password you Need.

Send Error message here!


Back to log-in

Close